﻿using System;
using System.Collections.Generic;
using System.Web;

namespace Util.IPInfoCollection
{
    public class IPInfo
    {
        public static string GetIPAddress(ref HttpContext context)
        {
            string strip = "";
            if (context.Request.ServerVariables["HTTP_VIA"] != null) // using proxy
            {
                strip = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();  // Return real client IP.
            }
            else// not using proxy or can't get the Client IP
            {
                strip = context.Request.ServerVariables["REMOTE_ADDR"].ToString(); //While it can't get the Client IP, it will return proxy IP.
            }
            return strip;
        }
    }
}